<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单</title>
    <link rel="stylesheet" type="text/css" href="../js/layer/css/layui.css">
    <link rel="stylesheet" type="text/css" href="../dialog/css/materialdesignicons.min.css">
    <link rel="stylesheet" type="text/css" href="../dialog/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../dialog/css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="../dialog/css/style.min.css">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <style>
        .field-select{
            border: none; background: none; font-size: 14px; opacity: 0.2; color: #4d5259;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
            appearance: none; /* 标准的语法 */
        }
    </style>
</head>
<body>
<form  class="layui-form">
    <div id="view">

        <div class="row">

            <div class="col-lg-12">
                <div class="card">



                    <!---验证还是走lay-->
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

                        <div class="layui-tab-content">

                            <!----分步骤表单--->
                            <div class="layui-tab-item layui-show">
                                <div class="col-md-12">
                                    {{#  arr_foreach(d, function(k, v){ }}
                                        {{#  if(v.input_type == 'hidden'){ }}
                                        {{#  }else if(v.input_type == 'password'){ }}
                                        {{#  }else if(v.input_type == 'image'){ }}
                                        {{#  }else if(v.input_type == 'images'){ }}
                                        {{#  }else if(v.input_type == 'video'){ }}
                                        {{#  }else if(v.input_type == 'videos'){ }}
                                        {{#  }else if(v.input_type == 'audio'){ }}
                                        {{#  }else if(v.input_type == 'audios'){ }}
                                        {{#  }else if(v.input_type == 'document'){ }}
                                        {{#  }else if(v.input_type == 'documents'){ }}
                                        {{#  }else if(v.input_type == 'select'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}</label>
                                            <div class="form-controls">
                                                <select lay-ignore class="form-control" name="{{v.field}}">
                                                    <option value="">请选择</option>
                                                    {{#  arr_foreach(v.value, function(k1, v1){ }}
                                                    {{#  if(k1 == v.default){ }}
                                                    <option value="{{k1}}" selected="">{{v1}}</option>
                                                    {{# }else{ }}
                                                    <option value="{{k1}}">{{v1}}</option>
                                                    {{#  } }}
                                                    {{#  }); }}
                                                </select>
                                            </div>
                                        </div>
                                        {{#  }else if(v.input_type == 'radio'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}

                                            </label>
                                            <div class="clearfix">
                                                <div class="custom-control custom-radio custom-control-inline">
                                                    <input checked lay-ignore type="radio" id="{{v.field}}---1" name="{{v.field}}" class="custom-control-input" value="">
                                                    <label class="custom-control-label" for="{{v.field}}---1">全部</label>
                                                </div>
                                                {{#  arr_foreach(v.value, function(k1, v1){ }}
                                                <div class="custom-control custom-radio custom-control-inline">
                                                    <input lay-ignore type="radio" id="{{v.field}}--{{k1}}" name="{{v.field}}" class="custom-control-input" value="{{k1}}">
                                                    <label class="custom-control-label" for="{{v.field}}--{{k1}}">{{v1}}</label>
                                                </div>
                                                {{#  }); }}
                                            </div>
                                        </div>

                                        {{#  }else if(v.input_type == 'date'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}</label>
                                            <input type="text" class="form-control inputTimerange" placeholder="请输入{{v.title}}" name="{{v.field}}" id="{{v.field}}" value="{{v.default}}">

                                        </div>

                                        {{#  }else if(v.input_type == 'cascader'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}</label>
                                            <div class="clearfix">
                                                <div class="cascader-prop" style="display: none;"> {"checkStrictly":true} </div>
                                                <input type="text" data-menuid="{{v.value_menu}}" class="form-control inputCascader" placeholder=""  name="{{v.field}}" id="{{v.field}}" value="{{v.default}}">
                                            </div>
                                        </div>

                                        {{#  }else if(v.input_type == 'time'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}</label>
                                            <input type="text" class="form-control inputTimerange" placeholder="请输入{{v.title}}" name="{{v.field}}" id="{{v.field}}" value="{{v.default}}">

                                        </div>

                                        {{#  }else if(v.input_type == 'timerange'){ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}</label>
                                            <input type="text" class="form-control inputTimerange" placeholder="请输入{{v.title}}" name="{{v.field}}" id="{{v.field}}" value="{{v.default}}">

                                        </div>

                                        {{# }else{ }}
                                        <div class="form-group">
                                            <label for="{{v.field}}">{{v.title}}
                                            <select class="field-select" lay-ignore id="select-{{v.field}}">
                                                <option value="=">等于</option>
                                                <option value="like">包含</option>
                                                <option value="!=">不等于</option>
                                                <option value=">=">大于等于</option>
                                                <option value="<=">小于等于</option>
                                            </select></label>
                                            <input type="text" class="form-control" placeholder="请输入{{v.title}}" name="{{v.field}}" id="{{v.field}}" value="{{v.default}}">

                                        </div>
                                        {{#  } }}


                                    {{#  }); }}
                                </div>
                            </div>

                        </div>

                        <div class="col-xs-12" id="from-button" style="text-align: center;">
                            <button type="button" class="btn btn-primary" lay-submit lay-filter="onsubmit" data-tabindex="0" id="submitButton">搜&nbsp;&nbsp;索</button>
                            <button type="button" class="btn btn-yellow" lay-submit lay-filter="onexport" data-tabindex="0" id="exportButton">导&nbsp;&nbsp;出</button>
                        </div>
                    </div>

                </div>
            </div>


        </div>

    </div>
</form>
<script type="text/javascript" src="../js/layer/layui.js"></script>
<script>
    ready(function() {

        layui.use(['zhanshop','form', 'zhanshopFrom'], function(){
            var menuId = parent.layui.zhanshop.getParam('_id');
            const IDNAME = parent.layui.zhanshop.table.idName;
            window.schmas = null;
            
            
            var searchView = function (url, elem, callback, reqMethod = 'POST', data = '', head = {}) {
                var view = $(elem).html();
                layui.zhanshop.ajax(url, reqMethod, data, head, function(res){
                    for(var i in parent.where){
                        if(res.data[i] != undefined){
                            res.data[i]['default'] = parent.where[i]
                        }
                    }
                    var conditions = {}
                    for(var i in parent.where['search']){
                        var item = parent.where['search'][i];
                        var field = item[0];
                        if(res.data[field] !== undefined && res.data[field]['default'] !== undefined){
                            if(res.data[field]['input_type'] == 'time' && res.data[field]['type'].indexOf("int") > -1){
                                var arr = item[2].split(',');
                                var arr0 = arr[0].trim();
                                var arr1 = arr[1].trim();
                                res.data[field]['default'] = date(arr0)+' , '+date(arr1);
                            }else{
                                res.data[field]['default'] = item[2];
                                conditions[field] = item[1];
                            }
                        }
                    }
                    laytpl($(elem).html()).render(res.data, function(html){
                        $(elem).html(html);
                        //渲染成功回调
                        if(callback != undefined){
                            callback(res.data);
                        }

                        for(name in conditions){
                            var condition = conditions[name]
                            $("#select-"+name).val(condition)
                        }

                    });
                }, function(xhr){
                    zhanshop.alert('页面渲染失败:'+(xhr.responseJSON[apiMsg] ? xhr.responseJSON[apiMsg] : xhr.statusText), 'danger', function(){
                        window.location.reload();
                    });
                });
            }

            searchView(API_ADDRESS+apiUrlTable+'/'+menuId, '#view', function(data){
                schmas = data;
                layui.zhanshopFrom.render();
                // 表单提交的处理
                //监听提交
                layui.form.on('submit(onsubmit)', function(data){
                    window.submitData = data.field;
                    delete submitData['select'];
                    layui.zhanshopFrom.searchhandle(submitData, function(res){
                        parent.where['_method'] = 'GET';
                        parent.where['search'] = res;
                        //parent.layui.zhanshop.table.rowObj.update(updateData[0])

                        parent.layui.zhanshopTable.render(parent.colsData, true);
                        // 关闭当前
                        parent.layer.closeAll();
                    }, true, false);

                    return false;
                });

                layui.form.on('submit(onexport)', function(data){
                    // 创建一个临时表单实现下载
                    window.submitData = data.field;
                    delete submitData['select'];
                    layui.zhanshopFrom.searchhandle(submitData, function(res){
                        parent.where['_method'] = 'export';
                        parent.where['search'] = res;
                        parent.layui.zhanshopTable.export(parent.colsData, true);
                        // // 关闭当前
                        parent.layer.closeAll();
                    }, true, false);

                    return false;
                });
            }, 'POST', {"_method": "searchfrom"});
        });

    });
</script>
</body>
</html>
